package com.caimiao.miao.page.master.system.server;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.caimiao.miao.R;
import com.caimiao.miao.interfaces.BaseFragmentImpl;
import com.caimiao.miao.page.master.MasterActivity;

public class ServerFragment extends BaseFragmentImpl<IServerContact.Presenter> implements IServerContact.View, View.OnClickListener {
    private EditText mEtServer;

    @Override
    public int getLayoutRes() {
        return R.layout.fragment_system_server;
    }

    @Override
    public void initUI() {
        setTitle("修改服务器地址");
        mEtServer = mRootView.findViewById(R.id.systemServerEtUrl);
    }

    @Override
    public void initLogic() {
        mRootView.findViewById(R.id.systemServerBtnSave).setOnClickListener(this::onClick);
        mRootView.findViewById(R.id.systemServerBtnCancel).setOnClickListener(this::onClick);
        new ServerPresenter(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.systemServerBtnSave:
                mPresenter.save(getUrl());
                break;
            case R.id.systemServerBtnCancel:
                close(null);
                break;
        }
    }

    @Override
    public void setUrl(String url) {
        mEtServer.setText(url);
    }

    @Override
    public String getUrl() {
        return mEtServer.getText().toString();
    }

    @Override
    public void close(Bundle extra) {
        MasterActivity activity = (MasterActivity) getActivity();
        activity.popBackFragment();
    }
}
